﻿using System;
using Loki.UI;
using Loki.UI.Win;
using Luna.UI.Accounting;

namespace Luna.UI.Win.Accounting
{
    /// <summary>
    /// Accounting category list view.
    /// </summary>
    public partial class AccountingCategoryListView : LunaView, IView<AccountingCategoryListViewModel>
    {
        public AccountingCategoryListView()
        {
            InitializeComponent();
            this.BindingChanged += AccountingCategoryListView_BindingChanged;

            _GridRules = new GridRule<DisplayNamedEntity>[]
            {
                new GridRule<DisplayNamedEntity>() { Column = COL_Description, ErrorMessage = Messages.UIMessages.REQUIRED_NAMEDVALUE_DESCRIPTION, Validator = x => !string.IsNullOrWhiteSpace(x.Description) },
                new GridRule<DisplayNamedEntity>() { Column = COL_Nom, ErrorMessage = Messages.UIMessages.REQUIRED_NAMEDVALUE_NAME, Validator = x => !string.IsNullOrWhiteSpace(x.Name) }
            };
        }

        private GridRule<DisplayNamedEntity>[] _GridRules;

        private void AccountingCategoryListView_BindingChanged(object P_Sender, EventArgs e)
        {
            VIEW_Category.Configure(
                ViewModel.Categories,
                x => string.Format(Messages.UIMessages.DELETE_ACCOUNT_CATEGORY, x.Name),
                _GridRules);
        }

        public new AccountingCategoryListViewModel ViewModel
        {
            get { return (AccountingCategoryListViewModel)base.ViewModel; }
            set { base.ViewModel = value; }
        }
    }
}